package com.lagou.edu.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.util.Set;

public class UrlMatch {

    public static boolean match(Set<String> patternPaths, String requestPath) {
        for (String patternPath : patternPaths) {
            boolean match = match(patternPath, requestPath);
            if (match) {
                return true;
            }
        }
        return false;
    }

    public static boolean match(String patternPath, String requestPath) {
        if (StringUtils.isEmpty(patternPath) || StringUtils.isEmpty(requestPath)) {
            return false;
        }
        PathMatcher matcher = new AntPathMatcher();
        return matcher.match(patternPath, requestPath);
    }

}